package com.attain.service.impl;

import com.attain.mapper.NewsMapper;
import com.attain.pojo.News;
import com.attain.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class NewsServiceImpl implements NewsService {
    @Autowired
    private NewsMapper newsMapper;

    @Override
    public void addNews(News news, Integer userId) {
        news.setCreateTime(LocalDateTime.now());
        news.setCreateUserId(userId);
        newsMapper.add(news);
    }

    @Override
    public List<News> getAllNews() {
        return newsMapper.findAll();
    }

    @Override
    public News getNewsById(Integer id) {
        return newsMapper.findById(id);
    }

    @Override
    public void updateNews(News news) {
        newsMapper.update(news);
    }

    @Override
    public void deleteNews(Integer id) {
        newsMapper.delete(id);
    }
}